﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using AspNetCs.Common;
using AspNetCs.Bll;

public partial class NewsInfoShow :BasePage
{
    protected int articleId = 0;
    protected int articleClassId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            articleId = StringHelper.isNumber_int(Request["ArticleId"]);
            articleClassId = StringHelper.isNumber_int(Request["ArticleClassId"]);
            ViewState["articleId"] = articleId;
            ViewState["articleClassId"] = articleClassId;
            AddAccessCount();
            DataBindReapter();
        }
        else
        {
            if (ViewState["articleClassId"]!=null)
            {
                articleClassId = StringHelper.isNumber_int(ViewState["articleClassId"].ToString());
            }
            if (ViewState["articleId"] != null)
            {
                articleId = StringHelper.isNumber_int(ViewState["articleId"].ToString());
            }
        }
    }

    //增加点击
    public void AddAccessCount()
    {
        string cmdText = "update Article set Hits=Hits+1 where ArticleId={0}";
        cmdText = string.Format(cmdText,this.articleId);
        ExcuteSqlTextBLL.ExcuteResult(cmdText);
    }

    public DataTable NextInfo()
    {
        DataTable dataTable = new DataTable();
        string cmdText = "select top 1 *from Article where ArticleId<{0} and ClassID={1} order by ArticleId desc";
        cmdText = string.Format(cmdText,this.articleId,this.articleClassId);
        dataTable = ExcuteSqlTextBLL.GetDataTable(cmdText);
        return dataTable;
    }

    public DataTable PreInfo()
    {
        DataTable dataTable = new DataTable();
        string cmdText = "select top 1 *from Article where ArticleId>{0} and ClassID={1} order by ArticleId asc";
        cmdText = string.Format(cmdText, this.articleId, this.articleClassId);
        dataTable = ExcuteSqlTextBLL.GetDataTable(cmdText);
        return dataTable;
    }


    public DataTable NewsDetail()
    {
        DataTable dataTable = new DataTable();
        string cmdText = "select *from Article where ArticleId={0}";
        cmdText = string.Format(cmdText, this.articleId);
        dataTable = ExcuteSqlTextBLL.GetDataTable(cmdText);
        return dataTable;
    }


    public DataTable HotNews()
    {
        DataTable dataTable = new DataTable();
        string cmdText = "select top 5 *from Article where ClassID={0} and IsHot=1 order by Hits desc";
        cmdText = string.Format(cmdText,this.articleClassId);
        dataTable = ExcuteSqlTextBLL.GetDataTable(cmdText);
        return dataTable;
    }

    public DataTable CommendNews()
    {
        DataTable dataTable = new DataTable();
        string cmdText = "select top 5 *from Article where ClassID={0} and IsCommend=1 order by ArticleId desc";
        cmdText = string.Format(cmdText, this.articleClassId);
        dataTable = ExcuteSqlTextBLL.GetDataTable(cmdText);
        return dataTable;
    }

    public DataTable LatestNews()
    {
        DataTable dataTable = new DataTable();
        string cmdText = "select top 5 *from Article where ClassID={0}  order by ArticleId desc";
        cmdText = string.Format(cmdText, this.articleClassId);
        dataTable = ExcuteSqlTextBLL.GetDataTable(cmdText);
        return dataTable;
    }


    public void DataBindReapter()
    {
        rptNextNews.DataSource = NextInfo();
        rptNextNews.DataBind();

        rptPreNews.DataSource = PreInfo();
        rptPreNews.DataBind();

        rptNewsDetail.DataSource = NewsDetail();
        rptNewsDetail.DataBind();

        rptLastestNews.DataSource = LatestNews();
        rptLastestNews.DataBind();

        rptHotNews.DataSource = HotNews();
        rptHotNews.DataBind();

        rptCommendNews.DataSource = CommendNews();
        rptCommendNews.DataBind();

    }
}
